package com.tobeface.wechat.showcase.handler;

import com.google.common.base.Objects;
import com.tobeface.wechat.message.WeChatMessage;
import com.tobeface.wechat.message.WeChatMessageBuilder;
import com.tobeface.wechat.message.WeChatMessageChannel;
import com.tobeface.wechat.message.handler.EventMessageHandlerSupport;

/**
 * @author loudyn
 */
public class SubscribeEventMessageHandler extends EventMessageHandlerSupport {

    @Override
    protected boolean isEventMessageSupport(WeChatMessage message, String event) {
        return Objects.equal("subscribe", event);
    }

    @Override
    protected void onEventMessageReceived(WeChatMessageChannel channel, WeChatMessage message, String event) {
        WeChatMessage outMessage = WeChatMessageBuilder.replyText(message).content("欢迎关注").build();
        channel.writeMessage(outMessage);
        channel.flush();
    }
}
